﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="quiz-list.aspx.cs" Inherits="VQWEB.administrator.huongnghiep.quiz.quiz_list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <div class="table-responsive">
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("add");
        var url_ashx = "/admin/huongnghiep/quiz/handler";
        var url_list = '<%=ResolveUrl("~/administrator/templates/list.tpl") %>';
        $(document).ready(function () {
            $.get(url_ashx, { list_quiz: "list_quiz" }, function (data) {
                list(data);
            });
        });

        $(document).on("click", "#btnAdd", function () {
            window.location = "/admin/huongnghiep/quiz/add";
        });

        $(document).on("click", "#btnEdit", function () {
            var Id = $("input[name='chkItem']:checked").first().attr("value");
            if (Id != undefined)
                window.location = "/admin/huongnghiep/quiz/edit/" + Id;
        });
        //LockUnLock
        $(document).on("click", "#btnLockUnlock", function () {
            var array = InputChecked();
            if (array.length > 0) {
                $.post(url_ashx, { lockunlock_quiz: JSON.stringify(array) }, function (data) {
                    list(data);
                });
            }
        });
        //Delete
        $(document).on("click", "#btnDelete", function (e) {
            var array = InputChecked();
            if (array.length > 0) {
                if (confirm("Bạn muốn xóa bản ghi không ???")) {
                    $.post(url_ashx, { delete_quiz: JSON.stringify(array) }, function (data) {
                        list(data);
                    });
                }
            }

        });

        //List
        function list(data) {
            var plusData = $.parseJSON(data);
            var columns = ["STT", "<input name='chkAll' value='' type='checkbox'>", "Giá trị", "Nội dung", "Trạng thái"];
            var rows = new Array();
            $.each(plusData, function (i, obj) {
                var row = [];
                var active = (obj.active) ? "Kích hoạt" : "Chưa kích hoạt";
                var url = "<a href=/admin/huongnghiep/quiz/view/" + obj.id + ">" + obj.value + "</a>";
                var checkbox = "<input name='chkItem' type='checkbox'  value=" + obj.id + ">";
                row.push(i + 1);
                row.push(checkbox);
                row.push(url);
                row.push(obj.noidung);
                row.push(active);
                rows.push(row);
            });
            $('div.table-responsive').empty();
            $.jqoteload(url_list, function (templates) {
                $('div.table-responsive').jqoteapp(templates.list_tpl, { columns: columns, rows: rows });
            });
        }
    </script>
</asp:Content>
